﻿using System.Net.Mail;
using System.Text.RegularExpressions;

namespace Obsidian.Tools
{
    public class Mail
    {
        public static bool Send(string toMail, string fromMail, string mailBody, string mailSubject, bool bcc)
        {
            if ((new Regex("\\w{1,}@\\w{1,}\\.\\w{1,}")).IsMatch(toMail))
                try
                {
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(fromMail);
                    //mail.ReplyTo = new MailAddress(fromMail);
                    if (!bcc)
                        mail.To.Add(toMail);
                    else
                        mail.Bcc.Add(toMail);   //暗送

                    mail.Body = mailBody;
                    mail.Subject = mailSubject;
                    //mail.CC.Add(toMail);
                    mail.IsBodyHtml = true;

                    SmtpClient sc = new SmtpClient();
                    sc.Host = "61.141.32.117";
                    sc.Port = 25;
                    sc.Credentials = new System.Net.NetworkCredential("ezeem", "wk8fa93pq3");
                    sc.DeliveryMethod = SmtpDeliveryMethod.Network;

                    sc.Send(mail);
                    return true;
                }
                catch
                {
                    return false;
                }
            else
            {
                return false;
            }

        }
    }
}
